package com.outfood.api.controller;

import com.rys.common.core.domain.AjaxResult;
import com.tps.open.oss.UploadService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("api/upload")
public class UploadController {
    
    @Reference
    UploadService uploadService;

    @ResponseBody
    @RequestMapping("/data")
    public AjaxResult upload(@RequestParam("file") MultipartFile[] files,
                          HttpServletRequest request) throws IOException {
        Long startTime = System.currentTimeMillis();
        String result = null;
        for (MultipartFile multipartFile : files) {
             result = uploadService.upload(multipartFile.getBytes());
        }
        Long endTime = System.currentTimeMillis();

        return AjaxResult.success(result);
    }
}

